package controller

import (
	"io"

	"goweb/controllers/auth"
	"goweb/controllers/curllook"
	"goweb/controllers/goldeye"
	"goweb/ext/settings"

	"github.com/DeanThompson/ginpprof"
	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {

	gin.DefaultWriter = io.MultiWriter(conf.Logger)
	r := gin.New()

	// r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	r.POST("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "ping",
		})
	})

	gold := r.Group("/goldeye")
	//gold.Use(middleware.JWT())
	{
		gold.GET("/getFeedBack", goldeye.GetFeedBack)
		gold.GET("/updateFeedBack", goldeye.UpdateFeedBack)
		//测试mongo
		//gold.POST("/mongo", goldeye.Test)
	}

	look := r.Group("/url")
	{
		look.GET("/CronInfo", curllook.CronInfo)
		look.POST("/CronInfo", curllook.AddUrlLookCron)
		look.GET("/CronTask", curllook.GetCronTask)
		//look.POST("/CronTask", curllook.AddCronTask)
	}

	user := r.Group("/user")
	user.POST("/auth", auth.Auth)
	user.POST("/logout", auth.Logout)
	user.POST("/addUser", auth.AddUser)
	// user.Use(middleware.JWT())
	user.Use()
	{
		user.GET("/getUserPer", auth.GetUserPer)
		user.GET("/getAllPer", auth.GetAllPer)
		user.POST("/updateUser", auth.UpdateUser)
		user.POST("/addRole", auth.AddRole)
		user.POST("/updateUserPer", auth.UpdateUserPer)

		//这有问题
		user.GET("/GetAllSource", auth.GetAllSource)
		user.POST("/AddSource", auth.AddSource)
		user.POST("/DeleteSource", auth.DeleteSource)
	}
	//r.GET("/GetReFeed", kadmin.GetReFeed)
	//apiv1 := r.Group("/api/v1")
	//apiv1.Use(middleware.JWT())
	//{
	//	apiv1.GET("/test", v1.Demo)
	//
	//	apiv1.GET("/UpdateReFeed", kadmin.UpdateReFeed)
	//	apiv1.GET("/InsertReFeed", kadmin.InsertReFeed)
	//
	//}
	ginpprof.Wrap(r)
	return r
}
